// 购物车API模块

import request from '@/utils/request'

/**
 * 获取购物车商品信息
 * @param {String} skuId SKUID
 * @returns Promise
 */
export const getNewCartGoods = (skuId) => {
  return request(`/goods/sku/${skuId}`, 'get')
}

/**
 *合并购物车
 * @param {String} skuId 商品skuId
 * @param {String} selected 是否选中
 * @param {String} count 数量
 * @returns
 */
export const mergeLocalCart = (cartList) => {
  console.log(cartList)
  return request('/member/cart/merge', 'post', cartList)
}

/**
 * 获取购物车列表
 * @returns
 */
export const findCartList = () => {
  return request('/member/cart', 'get')
}

/**
 * 加入购物车
 * @param {*} skuId 商品skuId
 * @param {*} count 商品数量
 * @returns
 */
export const insetCart = ({ skuId, count }) => {
  return request('/member/cart', 'post', { skuId, count })
}

/**
 * 删除/清空购物车
 * @param {Object} ids skuId集合
 * @returns Promise
 */
export const deleteCart = (ids) => {
  return request('/member/cart', 'delete', { ids })
}

/**
 * 修改购物车商品状态与数量
 * @param {String} id skuId
 * @returns Promise
 */
export const updateCart = (goods) => {
  return request(`/member/cart/${goods.skuId}`, 'put', { selected: goods.selected, count: goods.count })
}

/**
 * 购物车的全选与反选
 * @param {Boolean} selected 是否选中
 * @param {Object} ids skuId集合
 * @returns Promise
 */
export const checkAllCart = ({ selected, ids }) => {
  return request('/member/cart/selected', 'put', { selected, ids })
}
